import React from 'react'
import {connect} from 'react-redux'
import {Redirect,Route, Switch} from 'react-router-dom'
import { Layout, } from 'antd';




import Header from '../../compnents/header/header'
import Leftnav from '../../compnents/leftnav/leftnav'
import './admin.less'

import Home from '../home/home'
// import Category from '../products/category/category'
// import Product from '../products/product/product'
// import Role from '../role/role'
import User from '../user/user'
// import Bar from '../charts/bar/bar'
// import Line from '../charts/line/line'
// import Pie from '../charts/pie/pie'


const {  Footer, Sider, Content } = Layout;


class Admin extends React.Component{
    
   


   
    render(){
         const user = this.props.user
           // 如果内存没有存储user ==> 当前没有登陆
         if(!user ||!user._id){
              // 自动跳转到登陆(在render()中)
            return <Redirect to='/login'/>
         }

        

        return (
            <Layout style={{height:'100%'}}>
                <Sider> 
                    <div className='logo'>XXX测试系统</div>
                    <Leftnav></Leftnav>
                </Sider>
                <Layout>
                    <Header>Header</Header>
                    <Content style={{backgroundColor: 'white'}}>
                        <Switch>
                            <Route path='/home' component={Home}/>
                            {/* <Route path='/category' component={Category}/>
                            <Route path='/product' component={Product}/>
                            <Route path='/role' component={Role}/> */}
                            <Route path='/user' component={User}/>
                            {/* <Route path='/charts/bar' component={Bar}/>
                            <Route path='/charts/line' component={Line}/>
                            <Route path='/charts/pie' component={Pie}/> */}
                            <Redirect to='/home' />
                        </Switch>
                    </Content>
                    <Footer style={{textAlign: 'center', color: '#aaaaaa'}}>推荐使用谷歌浏览器，可以获得更佳页面操作体验</Footer>      
                </Layout>    
          </Layout>
        )
    }
}


export default connect(
    state =>({user:state.user}),
    {}
)(Admin);
